home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH05 / PGM5_3.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-10-09  |  2.5 KB  |  125 lines

  1. ; Sample variable declarations
  2. ; This sample file demonstrates how to declare and access some single
  3. ; dimension array variables in an assembly language program.
  4. ;
  5. ; Randall Hyde
  6.  
  7.  
  8.         .386            ;Need to use some 80386 addressing
  9.         option    segment:use16    ; modes.
  10.  
  11. dseg        segment    para public 'data'
  12.  
  13. J        word    ?
  14. K        word    ?
  15. L        word    ?
  16. M        word    ?
  17.  
  18. JD        dword    0
  19. KD        dword    1
  20. LD        dword    2
  21. MD        dword    3
  22.  
  23. ; Some simple uninitialized array declarations:
  24.  
  25. ByteAry        byte    4 dup (?)
  26. WordAry        word    4 dup (?)
  27. DwordAry    dword    4 dup (?)
  28. RealAry        real8    4 dup (?)
  29.  
  30.  
  31. ; Some arrays with initialized values:
  32.  
  33. BArray        byte    0, 1, 2, 3
  34. WArray        word    0, 1, 2, 3
  35. DWArray        dword    0, 1, 2, 3
  36. RArray        real8    0.0, 1.0, 2.0, 3.0
  37.  
  38.  
  39. ; An array of pointers:
  40.  
  41. PtrArray    dword    ByteAry, WordAry, DwordAry, RealAry
  42.  
  43. dseg        ends
  44.  
  45.  
  46.  
  47.  
  48.  
  49. ; The following program demonstrates how to access each of the above
  50. ; variables.
  51.  
  52. cseg        segment    para public 'code'
  53.         assume    cs:cseg, ds:dseg
  54.  
  55. Main        proc
  56.         mov    ax, dseg    ;These statements are provided by
  57.         mov    ds, ax        ; shell.asm to initialize the
  58.         mov    es, ax        ; segment register.
  59.  
  60.  
  61. ; Initialize the index variables.  Note that these variables provide
  62. ; logical indices into the arrays.  Don't forget that we've got to
  63. ; multiply these values by the element size when accessing elements of
  64. ; an array.
  65.  
  66.         mov    J, 0
  67.         mov    K, 1
  68.         mov    L, 2
  69.         mov    M, 3
  70.  
  71. ; The following code shows how to access elements of the arrays using
  72. ; simple 80x86 addressing modes:
  73.  
  74.         mov    bx, J        ;AL := ByteAry[J]
  75.         mov    al, ByteAry[bx]
  76.  
  77.         mov    bx, K        ;AX := WordAry[K]
  78.         add    bx, bx        ;Index*2 since this is a word array.
  79.         mov    ax, WordAry[bx]
  80.  
  81.         mov    bx, L        ;EAX := DwordAry[L]
  82.         add    bx, bx        ;Index*4 since this is a double
  83.         add    bx, bx        ; word array.
  84.         mov    eax, DwordAry[bx]
  85.  
  86.         mov    bx, M        ;BX := address(RealAry[M])
  87.         add    bx, bx        ;Index*8 since this is a quad
  88.         add    bx, bx        ; word array.
  89.         add    bx, bx
  90.         lea    bx, RealAry[bx]    ;Base address + index*8.
  91.  
  92.  
  93. ; If you have an 80386 or later CPU, you can use the 386's scaled indexed
  94. ; addressing modes to simplify array access.
  95.  
  96.  
  97.         mov    ebx, JD
  98.         mov    al, ByteAry[ebx]
  99.  
  100.         mov    ebx, KD
  101.         mov    ax, WordAry[ebx*2]
  102.  
  103.         mov    ebx, LD
  104.         mov    eax, DwordAry[ebx*4]
  105.  
  106.         mov    ebx, MD
  107.         lea    bx, RealAry[ebx*8]
  108.  
  109.  
  110.  
  111. Quit:        mov    ah, 4ch        ;Magic number for DOS
  112.         int    21h        ; to tell this program to quit.
  113. Main        endp
  114.  
  115. cseg        ends
  116.  
  117. sseg        segment    para stack 'stack'
  118. stk        byte    1024 dup ("stack   ")
  119. sseg        ends
  120.  
  121. zzzzzzseg    segment    para public 'zzzzzz'
  122. LastBytes    byte    16 dup (?)
  123. zzzzzzseg    ends
  124.         end    Main
  125.